﻿using System.Data.Entity;
using System.Security.Principal;
using System.Web;
using Arch.Data;
using Arch.EF.Data;
using Arch.IoC;
using Arch.Samples.Data;
using Arch.Web.IoC;
using Microsoft.Practices.Unity;

namespace Arch.Samples.Mvc.Infrastructure
{
    public class DependencyContainer : ServerDependencyContainer
    {
        public override void RegisterTypes(IUnityContainer container)
        {
            container
                .RegisterType(typeof (IRepository<>), typeof (Repository<>))
                .RegisterType<IRepository, DbRepository>()
                .RegisterType<IPrincipal, IPrincipal>(new InjectionFactory(c => HttpContext.Current.User))
                .RegisterType<DbContext, DbContext>(
                    new PerRequestLifetimeManager<DbContext>(),
                    new InjectionFactory(
                        c =>
                            {
                                var context = new DbContext("name=Arch");
                                context.Configuration.ProxyCreationEnabled = true;
                                context.Configuration.LazyLoadingEnabled = true;
                                return context;
                            }))
                ;
        }
    }
}